import 'package:boss/ui/widget/alert/alert.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class QuitApp extends StatelessWidget {
  final Widget child;

  const QuitApp({
    Key key,
    this.child,
  }) : super(key: key);

  Future<bool> onWillPop(BuildContext context) async {
    showAlert(
      context,
      content: '是否退出App？',
      onCancel: (context) {
        Navigator.pop(context);
      },
      onConfirm: (context) {
        SystemChannels.platform.invokeMethod('SystemNavigator.pop');
      },
    );
    return false;
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () => onWillPop(context),
      child: child,
    );
  }
}
